<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>

    var findJudge = function (n, trust) {
      const cnts = new Array(n + 1), out = new Array(n + 1)
      cnts.fill(0)
      out.fill(0)
      for (const t of trust) {
        cnts[t[1]]++
        out[t[0]]++
      }
      for (let i = 1; i <= n; i++)
        if (out[i] == 0 && cnts[i] == n - 1)
          return i
      return -1

    };
    console.log(findJudge(n = 3, trust = [[1, 3], [2, 3]]))

  </script>
</body>

</html>